#include <iostream>

/**
 * PAT A 1093 Count PAT's
 */

static const long long MOD = 1000000007;

int main() {
    std::string str;
    std::cin >> str;
    long long nP = 0, nPA = 0, nPAT = 0;
    for (int i = 0; i < str.length(); i++) {
        char c = str[i];
        if (c == 'P')
            nP++;
        else if (c == 'A')
            nPA += nP;
        else {
            nPAT += nPA;
            nPAT %= MOD;
        }
    }
    printf("%lld", nPAT);
}